﻿using Architecture.Api.Application.Commands.SourceCommand;
using Architecture.Domian.Common;
using Architecture.Domian.DTO;
using Architecture.Domian.Entity;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Architecture.Api.Controllers
{
    /// <summary>
    /// 溯源管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class SourceController : ControllerBase
    {
        private readonly IMediator _mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public SourceController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<GoodsInfo>> GetGoodsList([FromQuery] SourceReadCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 添加溯源信息 
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> SourceInsert(SourceCreateCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 获取溯源信息列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PageResult<SourceInfoDTO>> GetSourceInfoList([FromQuery] SourceReadPageCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 根据溯源Id获取溯源信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SourceInfoDTO> GetSourceInfoById([FromQuery] SourceReadByIdCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 修改溯源信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> SourceUpdate(SourceUpdateCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 根据溯源Id逻辑删除溯源信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> SourceDelete([FromQuery] SourceDeleteCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 批量删除溯源信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> SourceBacthLogicDelete([FromQuery] SourceBatchDeleteCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 显示多张图片
        /// </summary>
        /// <param name="command">生产批次号</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<PictureDTO>> GetPicture([FromQuery] SourceQueryPicListCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 批量操作多图片
        /// </summary>
        /// <param name="command">生产批次号 图片路径</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> BatchPic(SourceBatchPicCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
